import 'package:flutter/material.dart';

class Animation1 extends StatefulWidget {
  const Animation1({super.key});
  @override
  State<StatefulWidget> createState() {
    return Animation1State();
  }
}

class Animation1State extends State with SingleTickerProviderStateMixin {
  late Animation<double> animation;
  late Animation<double> animation1;
  late Animation<double> animation2;
  late Animation<Color?> animation3;
  late Animation<int> animationText;
  late Animation<Rect?> animationRect;
  late Animation<Size?> animationSize;
  late AnimationController controller;
  @override
  void initState() {
    super.initState();
    controller = AnimationController(
        value: 0, duration: const Duration(seconds: 3), vsync: this);
    animation = Tween<double>(begin: 0, end: 255).animate(controller)
      ..addListener(() {
        if(mounted){
          setState(() {});
        }
      });
    animation1 = Tween<double>(begin: 100, end: 255).animate(controller)
      ..addListener(() {
        if(mounted){
          setState(() {});
        }
      });
    animation2 = Tween<double>(begin: 255, end: 0).animate(controller)
      ..addListener(() {
        if(mounted){
          setState(() {});
        }
      });
    animation3 =
        ColorTween(begin: Colors.brown, end: Colors.orange).animate(controller)
          ..addListener(() {
            if(mounted){
              setState(() {});
            }
        });
    animationText = IntTween(begin: 0, end: 10000)
        .animate(controller..duration = const Duration(seconds: 5))
      ..addListener(() {
        if(mounted){
              setState(() {});
            }
      });
    animationSize =
        SizeTween(begin: const Size(200, 100), end: const Size(300, 100))
            .animate(controller)
          ..addListener(() {
             if(mounted){
              setState(() {});
            }
        });
    animationRect = RectTween(
            begin: Rect.fromCircle(center: const Offset(100, 100), radius: 100))
        .animate(controller)
      ..addListener(() {
         if(mounted){
              setState(() {});
          }
      });
    // controller.forward();
    controller.repeat();
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(),
        body: Column(children: [
          Expanded(
              child: Container(
            alignment: Alignment.center,
            color: Color.fromARGB(255, animation.value.toInt(),
                animation1.value.toInt(), animation2.value.toInt()),
            child: const Text("animation double value"),
          )),
          Expanded(
              child: SizedBox(
            width: animationSize.value?.width,
            height: animationSize.value?.height,
            child: Container(
              alignment: Alignment.center,
              color: animation3.value,
              child: const Text("animation color value"),
            ),
          )),
          Expanded(
            flex: 2,
            child: Text("${animationText.value}"),
          ),
        ]));
  }
}
